package zb.blog.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zb.blog.base.bean.Result;
import zb.blog.base.cache.DataToCache;
import zb.blog.base.global.GlobalVar;
import zb.blog.dao.StatisticsDao;
import zb.blog.service.IStatisticsService;

import java.util.List;
import java.util.Map;

@Service
public class StatisticsService implements IStatisticsService {
    @Autowired
    private StatisticsDao statisticsDao;

    @Override
    public Result getCountMsg() {
        Result res = new Result();
        Map<String, Long> countMap = statisticsDao.getCountMsg();
        countMap.put("reqCount", DataToCache.reqStatistics.get("all"));
        countMap.put("mainPage", Long.valueOf(GlobalVar.MAIN_PAGE));
        countMap.put("subPage", Long.valueOf(GlobalVar.SUB_PAGE));
        res.setData(countMap);
        res.setSuccess(GlobalVar.SUCCESS);
        return res;
    }

    @Override
    public Result getReqOfDay() {
        Result res = new Result();
        List<Long> reqOfDay = DataToCache.reqOfDay;
        res.setData(reqOfDay);
        res.setSuccess(GlobalVar.SUCCESS);
        return res;
    }

    @Override
    public Result getReqPercent() {
        Result res = new Result();
        res.setData(DataToCache.reqStatistics);
        res.setSuccess(GlobalVar.SUCCESS);
        return res;
    }
}
